package com.oocl.ita.linstner.chatframe;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JList;
import javax.swing.JTextPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.oocl.ita.qqclientt.QQClient;
import com.oocl.ita.sakura.client.Client;

public class ToOneClientListener implements ListSelectionListener {
	JList jlist;
	JTextPane jtp1;

	public ToOneClientListener(JList jlist, JTextPane jtp1) {
		super();
		this.jlist = jlist;
		this.jtp1 = jtp1;
	}

	@Override
	public void valueChanged(ListSelectionEvent e) {
		/*
		 * 1. 更改 toClient 为选择的联系人
		 * 2. 刷新jtp1 ，显示该联系人的account
		 */
		// 1. 更改toclient
		System.out.println("ToOneClientListener : original ToClient" + QQClient.getToClient());
		if (jlist == null) {
			// 处理syn报文时会刷新联系人列表，但这时候不触发“更改toClient事件”
			System.out.println("jlist is null");
			return ;
		}
		Client destClient = ((Client) jlist.getSelectedValue());
		if (destClient == null) {
			System.out.println("destClient is null");
		}
		String selectedAccount = destClient.getAccout();
		QQClient.getToClient().setAccout(selectedAccount);
		System.out.println("ToOneClientListener : updated ToClient" + QQClient.getToClient());
		
		// 刷新 jtp1
		jtp1.setText("To  " + QQClient.getToClient().getAccout());
	}

}
